package com.cskaoyan.wordmemorize.controller.app;

import com.cskaoyan.wordmemorize.auth.StpKit;
import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayBookVocDTO;
import com.cskaoyan.wordmemorize.dto.app.DisplayChapterDTO;
import com.cskaoyan.wordmemorize.dto.app.UserBookStatisticsDTO;
import com.cskaoyan.wordmemorize.request.AppVocPageRequest;
import com.cskaoyan.wordmemorize.service.VocService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user/voc")
public class AppVocController {

    @Autowired
    VocService vocService;

    // APP端获取无章节的书籍单词列表
    @GetMapping("/book/display")
    public Result<PageDTO<DisplayBookVocDTO>> getDisplayBookVocsInfo(AppVocPageRequest pageRequest){
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId.toString());
        PageDTO<DisplayBookVocDTO> result = vocService.getDisplayBookVocsInfo(pageRequest);
        return Result.ok(result);
    }
    // APP端获取有章节的书籍单词列表
    @GetMapping("/book/chapter/display")
    public Result<PageDTO<DisplayChapterDTO>> getDisplayBookChapterVocsInfo(AppVocPageRequest pageRequest){
        Long userId = StpKit.USER.getLoginIdAsLong();
        pageRequest.setUserId(userId.toString());
        PageDTO<DisplayChapterDTO> result = vocService.getDisplayBookChapterVocsInfo(pageRequest);
        return Result.ok(result);
    }
    // APP端获取单词详情
    @GetMapping("/detail/{vocId}")
    public Result<VocDTO> getVocDetail(@PathVariable("vocId") Long vocId, Long userId){
        userId = StpKit.USER.getLoginIdAsLong();
        VocDTO result = vocService.getVocDetail(vocId, userId);
        return Result.ok(result);
    }
    //APP端目标书籍已选单词，未选单词数据
    @GetMapping("/{bookId}/selection/info")
    public Result<UserBookStatisticsDTO> getUserChooseCountInBook(Long userId, @PathVariable("bookId") Long bookId){
        userId = StpKit.USER.getLoginIdAsLong();
        UserBookStatisticsDTO result = vocService.getUserChooseCountInBook(userId, bookId);
        return Result.ok(result);
    }

}
